package ee.propaganda.gparrot.client.view;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import ee.propaganda.gparrot.client.model.ServiceInfo.ServiceType;

public class ServicePanel extends Composite{
	
	
	private VerticalPanel panel;
	private Label error;
	private VerticalPanel serviceRegistrationPanel;
	
	private Label serviceDescriptionLabel;
	private Label serviceNameLabel;
	private ServiceType st;
	private Button register;
	
	public ServicePanel(ServiceType st, boolean serviceRegistered) {
		this.st = st;
		//create service panel
		panel = new VerticalPanel();
		this.initWidget(panel);
		//add service name and error label
		setServiceNameLabel(st);
		panel.add(serviceNameLabel);
		error = new Label();
		panel.add(error);
		
		if(!serviceRegistered){
			serviceRegistrationPanel = new VerticalPanel();
			setServiceDescriptionLabel(st);			
			serviceRegistrationPanel.add(serviceDescriptionLabel);
			
			register = new Button("Register service");

			
			serviceRegistrationPanel.add(register);
			panel.add(serviceRegistrationPanel);
			
		} else {
			if(serviceRegistrationPanel != null)
				serviceRegistrationPanel.setVisible(false);
			panel.add(new Label("Your Google Wave service account is registered with us,\n but the notification service is still under construction."));
		}
		
	}
	
	public Label getError() {
		return error;
	}

	Button getRegisterButton(){
		return register;
	}
	
	public void setError(String error) {
		this.error.setText(error);
	}	

	public void setServiceDescriptionLabel(ServiceType st) {
		String serviceDescription;
		switch (st) {
		case WAVE:
		default:
			serviceDescription = "By registering your Google Wave account details here, you can receive notifications on new waves, wavelets and blips that your account receives.";
			break;
		}
		serviceDescriptionLabel = new Label(serviceDescription);
	}

	public void setServiceNameLabel(ServiceType st) {
		String serviceName;
		switch (st) {
		case WAVE:
		default:
			serviceName = "Google Wave";
			break;
		}
		serviceNameLabel = new Label(serviceName);
	}

	public ServiceType getServiceType() {
		return st;
	}

}
